473,422 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

How to add a drop down box in Python GUI

Hi,

How do i add a drop down box with few pre-populated strings in the same?
I could find list box and drop down menu in the HELP document of Python, but not drop down box.

Please help me in this.

Thanks,
BK
Nov 27 '06 #1
11 24185
bartonc
6,596 Expert 4TB
Hi,

How do i add a drop down box with few pre-populated strings in the same?
I could find list box and drop down menu in the HELP document of Python, but not drop down box.

Please help me in this.

Thanks,
BK
Tkinter does not have a combobox. If you are using Tkinter, I can supply a module that requires Python Image Library to make a drop-down menu + a text entry + graphics look like a combo box, but it may need some work first. I now use wxPython for GUI.
Nov 27 '06 #2
Tkinter does not have a combobox. If you are using Tkinter, I can supply a module that requires Python Image Library to make a drop-down menu + a text entry + graphics look like a combo box, but it may need some work first. I now use wxPython for GUI.

If that is so, could u please help me in this regard. Are there any pre requisites for the issue?

Thanks,
BK
Nov 27 '06 #3
bartonc
6,596 Expert 4TB
If that is so, could u please help me in this regard. Are there any pre requisites for the issue?

Thanks,
BK
I am unclear on which issue you want help with.
Nov 27 '06 #4
Hi,

My intention is to have a drop down box (with edit facility) which would have several ip addresses. The user either can select an existing one or else type a new ip.

I could find spinbox option but thats not editable.

So how do i create such a drop down box?

Thanks,
Badri
Nov 28 '06 #5
bartonc
6,596 Expert 4TB
Hi,

My intention is to have a drop down box (with edit facility) which would have several ip addresses. The user either can select an existing one or else type a new ip.

I could find spinbox option but thats not editable.

So how do i create such a drop down box?

Thanks,
Badri
You still have not said which GUI you are using. If you are using Tkinter, I can supply a class, but it will take me some time to make it work for you.
Nov 28 '06 #6
You still have not said which GUI you are using. If you are using Tkinter, I can supply a class, but it will take me some time to make it work for you.
Yes, I am using Tkinter.
Nov 28 '06 #7
bartonc
6,596 Expert 4TB
Yes, I am using Tkinter.
Ok, I'll tweek my module to work for you.
Nov 28 '06 #8
Would you include the code so everyone could benefit?


Ok, I'll tweek my module to work for you.
Mar 29 '07 #9
bartonc
6,596 Expert 4TB
Would you include the code so everyone could benefit?
Yep. I'll get right on it.
Mar 29 '07 #10
bartonc
6,596 Expert 4TB
Yep. I'll get right on it.
As promised:
Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2.  
  3. ## I have a working ComboBox which is editable and
  4. ## has a button around here some where. I'll keep
  5. ## looking for that. In the mean time, this Entry
  6. ## subclass shares a StringVar with the menu item
  7. ## that are created form input list(s) to achive a
  8. ## simple ChoiceBox.
  9.  
  10. class ChoiceBox(Entry):
  11.     """ComboBox(parent, itemList=[], *args, kwargs)
  12.        A simple ChoiceBox with checked menu items
  13.        itemList may be a mix of list of strings and lists of tuples of (label, list of strings)
  14.        for one level of sub menu items. *args and kwargs are passed to the Entry widget."""
  15.  
  16.     def __init__(self, parent, itemList=[], *args, **kwargs):
  17.         Entry.__init__(self, parent, *args, **kwargs)
  18.  
  19.         self.pyvar = pyvar = StringVar(self)    # this is the sharing mechanism
  20.         self.config(textvariable=pyvar)         # add the StringVar to self.
  21.  
  22.         self.popup = popup = Menu(self, tearoff=0)
  23.         self.bind("<Button-1>", self.mousedown, add="+")
  24.  
  25.         for item in itemList:
  26.             if type(item) == tuple:
  27.                 submenu = self.GetSubMenu(item[0])
  28.                 for subitem in item[1]:
  29.                     self.AddCBMenuItem(submenu, subitem)
  30.             else:
  31.                 self.AddCBMenuItem(popup, item)
  32.  
  33.     def GetSubMenu(self, label):
  34.         menu = Menu(self, tearoff=0)
  35.         self.popup.add_cascade(menu=menu, label=label)
  36.         return menu
  37.  
  38.     def AddCBMenuItem(self, menu, label):
  39.         menu.add_checkbutton(label=label,
  40.                              command=self.MenuSelect,
  41.                              variable=self.pyvar,   # add the StringVar to a menu.
  42.                              onvalue=label, offvalue='')
  43.  
  44.     def mousedown(self, event):
  45.         x = event.x_root - event.x
  46.         y = event.y_root -  event.y
  47.         self.popup.post(x, y)
  48.         return 'break'
  49.  
  50.     def get(self):
  51.         return self.pyvar.get()
  52.  
  53.     def clear(self):
  54.         self.pyvar.set('')
  55.  
  56.     def MenuSelect(self):
  57.         pass
  58.  
  59.  
  60.  
  61. if __name__ == '__main__':
  62.  
  63.  
  64.  
  65.     def _test():
  66.         root = Tk()
  67. ##        cb = ChoiceBox(root, [('test', ['one', 'two', 'three'])])
  68.         cb = ChoiceBox(root, ['one', 'two', 'three'])
  69.         cb.pack()
  70.         root.mainloop()
  71.  
  72.     _test()
  73.  
Mar 29 '07 #11
Cool code, but I don't see how to enable typing in a new entry...?
Apr 3 '15 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
2
by: ehm | last post by:
I am working on creating an editable grid (for use in adding, deleting, and editing rows back to an Oracle database). I have a JSP that posts back to a servlet, which in turns posts to a WebLogic...
3
by: Don Wash | last post by:
Hi There! I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to widen the Drop down box's Pull-Down list's width? I'm not talking about the Drop-down box's width but the box...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
4
by: Alex Hunsley | last post by:
Can anyone recommend some code for creating drop-down menus in tkinter? To be absolutely clear, here's an example of a drop-down: http://www.google.co.uk/preferences?hl=en (see the language...
3
by: bruce | last post by:
Hi... Never used python, but I have a question regarding Drop Down Menus. Does Python allow me to create a website, that will permit the user to create Drop Down menus that can be initiated with...
7
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.